<include file="./Public/Home/header.html" />
<div class="index modify">
    <div class="indexLog">
        <div class="indexTitle clear">
            <span class="indexIcon"></span>
            <span>绿贝雷快速学习特训营</span>
        </div>
    </div>
    <div class="indexContent">
        <div class="modify_title">
            <span>资料修改</span>
        </div>
        <div class="indexName">
            <label>士兵</label>
            <span>姓：</span>
            <input type="text" class="surname" value="{$userInfo['surname']}" data-text="士兵姓不能为空！" placeholder="张">
            <span class="nameMargin">名：</span>
            <input type="text" class="name" value="{$userInfo['name']}" data-text="士兵名不能为空！" placeholder="三">
        </div>
        <div class="indexPinyin">
            <label>拼音</label>
            <span>姓：</span>
            <input type="text" class="PinyinSurname" value="{$userInfo['PinyinSurname']}"  data-text="拼音姓不能为空！" placeholder="Zhang">
            <span>名：</span>
            <input type="text" class="PinyinName" value="{$userInfo['PinyinName']}"  data-text="拼音名不能为空！" placeholder="San">
        </div>
        <div class="indexNian clear">
            <div class="indexSui ">
                <span>年龄：</span>
                <input type="text" class="age" value="{$userInfo['age']}"  data-text="年龄不能为空！" placeholder="年龄">
            </div>
            <span>年级：</span>
            <div class="indexGrade indexAge">
                <div class="selectShow" data-id="1" onclick="selectShow(this)">
                    <div class="selectMin grade">
                        <input type="hidden" name="class_id" id="class_id" value="{$userInfo['class_id']}">
                        <span><?php echo M('class')->where(array('id'=>$userInfo['class_id']))->getField('name');?></span>
                    </div>
                    <span class="triangle"></span>
                </div>
                <ul class="selectList"  >
                    <volist name="class" id="val">
                        <li><a href="javascript:void(0)" data-id="{$val['id']}" data-value="{$val['id']}">{$val['name']}</a></li>
                    </volist>
                </ul>
            </div>
        </div>
        <div class="heightAndWeight clear">
            <div class="indexHeight">
                <span>身高(cm)：</span><input type="text" value="{$userInfo['height']}" class="height" data-text="身高不能为空！" placeholder="">
            </div>
            <div class="indexweight" style="margin: 0">
                <span>体重(kg)：</span><input type="text" class="weight" value="{$userInfo['weight']}" data-text="体重不能为空！"  placeholder="">
            </div>
        </div>
        <div class="indexPhone">
            <span>紧急联系电话:</span>
            <input type="text" class="phone" data-text="电话不能为空！" value="{$userInfo['phone']}"  placeholder="联系电话：">
        </div>
        <div class="relationship">
            <span>与士兵关系：</span>
            <input type="text" class="guanXi" value="{$userInfo['guanXi']}" placeholder="如母子">
        </div>
        <div class="indexImg">
            <form id="uploadForm">
                <img src="{$userInfo['head_img'] }" alt="">
                <input type="file" name="buyer_photo"  onchange="doUpload(this)" >
                <input type="hidden" name="head_img" id="head_img" value="{$userInfo['head_img'] }">
            </form>
        </div>
        <div class="Preservation">
            <a href="javascript:void(0)" onclick="Submit()" >保存</a>
        </div>
    </div>

    <div class="mongceng">
        <div class="mengBox">
            <p>图片上传中，请稍后...</p>
        </div>
    </div>

    <script>
        //快速提交
        function Submit() {
            $(".indexContent input[type='text']").each(function () {
                if (!$.trim($(this).val())) {
                    alert_fun($(this).attr("data-text"));
                    return false;
                }
            });
            var surname = $(".surname").val();                  //获取士兵姓
            var name = $(".name").val();                        //获取士兵名
            var PinyinSurname = $(".PinyinSurname").val();      //获取拼音姓
            var PinyinName = $(".PinyinName").val();         //获取拼音名
//            var gender = $(".gender").text();                   //获取性别
            var age = $(".age").val();                         //获取年龄
            var height = $(".height").val();                    //获取身高
            var weight = $(".weight").val();                    //获取体重
//            var phone = $(".phone").val();                      //获取电话
//            var code = $(".code").val();                        //获取验证码
            var guanXi = $(".guanXi").val();                    //获取关系
            var class_id = $("#class_id").val();            //获取班级id
            var head_img = $("#head_img").val();            //获取用户头像

            if(surname ==''){
                alert_fun('请输入士兵姓');
                return false;
            }
            if(name ==''){
                alert_fun('请输入士兵名');
                return false;
            }
            if(PinyinSurname ==''){
                alert_fun('请输入士兵姓拼音');
                return false;
            }
            if(PinyinName ==''){
                alert_fun('请输入士兵姓拼音');
                return false;
            }

            if(age ==''){
                alert_fun('请输入年龄');
                return false;
            }

            if(class_id ==0){
                alert_fun('请选择年级');
                return false;
            }

            if(height ==''){
                alert_fun('请输入身高');
                return false;
            }
            if(weight ==''){
                alert_fun('请输入体重');
                return false;
            }
//            if(phone ==''){
//                alert_fun('请输入电话号码');
//                return false;
//            }
//
//            if(code ==''){
//                alert_fun('请输入验证码');
//                return false;
//            }
            if(guanXi ==''){
                alert_fun('请输入与士兵的关系');
                return false;
            }
            if(head_img ==''){
                alert_fun('请上传头像');
                return false;
            }
            $.ajax({
                url: "{:U('update')}",
                type: 'post',
                data: {
                    'surname':surname,
                    'name':name,
                    'PinyinSurname':PinyinSurname,
                    'PinyinName':PinyinName,
                    'age':age,
                    'height':height,
                    'weight':weight,
//                    'phone':phone,
//                    'code':code,
                    'guanXi':guanXi,
                    'class_id':class_id,
                    'head_img':head_img
                },
                dataType: "json",
                success: function (json) {
                    if (json.status) {
                        alert_fun(json.error);
                    } else {
                        alert_fun(json.error);
                    }
                }
            })
        }

        //图片上传
        function doUpload(that) {
            var formData = new FormData($( "#uploadForm" )[0]);
            if (that.files && that.files[0]) {
                var kb = (that.files[0].size / 1024).toFixed(0);
                if (kb > (1024*10)) {
                    alert_fun("上传大小不能超过10MB");
                    return false;
                }
            }
            $(".mongceng").show();
            $.ajax({
                url: "{:U('upload')}",
                type: 'post',
                data: formData,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                dataType:"json",
                success: function (json) {
                    $(".mongceng").hide();
                    if (json.status) {
                        $("#uploadForm img").attr("src",json.data);
                        $("#head_img").val(json.data);
                    } else {
                        alert_fun(json.error);
                    }
                },
                error: function (returndata) {
                    $(".mongceng").hide();
                    alert_fun(returndata.status);
                }
            });
        }

    </script>
    <include file="./Public/Home/nav.html" />
</div>
<include file="./Public/Home/footer.html" />